using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace ValidationFramework.Reflection
{
	public class CachedFieldInfo : CachedInfoBase
	{
		internal readonly FieldInfo fieldInfo;

		/// <summary>
		/// Gets a value indicating whether the <see cref="FieldDescriptor"/> is static. 
		/// </summary>
		public bool IsStatic
		{
			get;
			private set;
		}

		internal CachedFieldInfo(FieldInfo fieldInfo)
			: base(fieldInfo.FieldType.TypeHandle, fieldInfo.Name)
		{
			if (fieldInfo.FieldType.IsGenericParameter)
			{
				throw new ArgumentException("fieldInfo cannot be a genetic type.", "fieldInfo");
			}
			//TODO: Use Dynamic method instead
			this.fieldInfo = fieldInfo;
			IsStatic = fieldInfo.IsStatic;
		}

		/// <inheritdoc />
		public override object GetValue(object instance)
		{
			return fieldInfo.GetValue(instance);
			//return invoker(target);
		}
	}
}
